thread = love.thread.getThread()
print(thread)

require "wx"
require "luagl"

frame = nil
function createWin()
xpcall(function()

function glInit()
	local size = frame:GetClientSize()
	local width, height = size:GetWidth(),size:GetHeight()
	
	context:SetCurrent(canvas)
	--print("GLInit")
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, width,height ,0, 0,1)
	gl.Viewport(0,0,width,height)
	
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
end
function render()
	gl.ClearColor(0,0,0,1)
	gl.Clear(gl.COLOR_BUFFER_BIT + gl.DEPTH_BUFFER_BIT)
	gl.LoadIdentity()
	
	gl.Begin(gl.QUADS)
		gl.Vertex(0, 0, 0)
		gl.Vertex(64, 0, 0)
		gl.Vertex(64, 64, 0)
		gl.Vertex(0, 64, 0)
	gl.End()
	
	canvas:SwapBuffers()
end

frame = wx.wxFrame( wx.NULL, wx.wxID_ANY, "wxLua + LuaGL Demo",
					wx.wxDefaultPosition, wx.wxSize(450,450), 
					wx.wxDEFAULT_FRAME_STYLE)
				
--this is where the GLCanvas is created
canvas = wx.wxGLCanvas(frame, wx.wxID_ANY, 
						wx.wxDefaultPosition,
						wx.wxDefaultSize,
						wx.wxEXPAND)
context = wx.wxGLContext(canvas)
--print("Hooking GLCanvas Paint")
canvas:Connect(wx.wxEVT_PAINT, render)
glInit()
canvas:Refresh()

print("Starting app loop")
frame:Show(true)
wx.wxGetApp():MainLoop()
print("Ending app loop")
end, function(err)
	print(err)
end)

end
createWin()
--